package com.danjinwulian.web.controller.iot;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.danjinwulian.common.core.domain.entity.IotHotel;
import com.danjinwulian.device.service.IIotHotelService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.danjinwulian.common.annotation.Log;
import com.danjinwulian.common.core.controller.BaseController;
import com.danjinwulian.common.core.domain.AjaxResult;
import com.danjinwulian.common.enums.BusinessType;
import com.danjinwulian.common.utils.poi.ExcelUtil;
import com.danjinwulian.common.core.page.TableDataInfo;

/**
 * 酒店公寓Controller
 * 
 * @author ken.h
 * @date 2022-08-23
 */
@RestController
@RequestMapping("/device/hotel")
public class IotHotelController extends BaseController
{
    @Autowired
    private IIotHotelService iotHotelService;

    /**
     * 查询酒店公寓列表
     */
    @PreAuthorize("@ss.hasPermi('device:hotel:list')")
    @GetMapping("/list")
    public TableDataInfo list(IotHotel iotHotel)
    {
        startPage();
        List<IotHotel> list = iotHotelService.selectIotHotelList(iotHotel);
        return getDataTable(list);
    }

    /**
     * 导出酒店公寓列表
     */
    @PreAuthorize("@ss.hasPermi('device:hotel:export')")
    @Log(title = "酒店公寓", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IotHotel iotHotel)
    {
        List<IotHotel> list = iotHotelService.selectIotHotelList(iotHotel);
        ExcelUtil<IotHotel> util = new ExcelUtil<IotHotel>(IotHotel.class);
        util.exportExcel(response, list, "酒店公寓数据");
    }

    /**
     * 获取酒店公寓详细信息
     */
    @PreAuthorize("@ss.hasPermi('device:hotel:query')")
    @GetMapping(value = "/{hotelId}")
    public AjaxResult getInfo(@PathVariable("hotelId") Long hotelId)
    {
        return AjaxResult.success(iotHotelService.selectIotHotelByHotelId(hotelId));
    }

    /**
     * 新增酒店公寓
     */
    @PreAuthorize("@ss.hasPermi('device:hotel:add')")
    @Log(title = "酒店公寓", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IotHotel iotHotel)
    {
        return toAjax(iotHotelService.insertIotHotel(iotHotel));
    }

    /**
     * 修改酒店公寓
     */
    @PreAuthorize("@ss.hasPermi('device:hotel:edit')")
    @Log(title = "酒店公寓", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IotHotel iotHotel)
    {
        return toAjax(iotHotelService.updateIotHotel(iotHotel));
    }

    /**
     * 删除酒店公寓
     */
    @PreAuthorize("@ss.hasPermi('device:hotel:remove')")
    @Log(title = "酒店公寓", businessType = BusinessType.DELETE)
	@DeleteMapping("/{hotelIds}")
    public AjaxResult remove(@PathVariable Long[] hotelIds)
    {
        return toAjax(iotHotelService.deleteIotHotelByHotelIds(hotelIds));
    }
}
